package com.baozhun.mall.common.widget.customview.addresspicker

import android.view.View
import com.baozhun.mall.common.BR
import com.baozhun.mall.common.R
import com.baozhun.mall.common.base.BaseListAdapter
import com.baozhun.mall.common.databinding.ItemClassifyLayoutBinding
import com.baozhun.mall.common.databinding.ItemRegionBinding
import com.baozhun.mall.common.model.bean.ClassifyInfo
import com.baozhun.mall.common.model.bean.RegionBean
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder

/**
 * @Title：
 * @Description：
 * @Author：xing.luo
 * @Since：2022/12/19
 * @Version：1.0.0
 */
class CommonPickerAdapter(data: MutableList<RegionBean>?) :
    BaseListAdapter<RegionBean, ItemRegionBinding>(R.layout.item_region, data) {

    override fun convert(holder: BaseDataBindingHolder<ItemRegionBinding>, item: RegionBean) {
        holder.dataBinding?.setVariable(BR.model, item)
        holder.dataBinding?.prefixIv?.visibility = if (item.isShow) View.VISIBLE else View.INVISIBLE
        item.isSelect = (item.name == AddressPickerDialog.currentAddress?.province ||
                item.name == AddressPickerDialog.currentAddress?.street ||
                item.name == AddressPickerDialog.currentAddress?.county ||
                item.name == AddressPickerDialog.currentAddress?.city
                )
        if (item.isSelect) {
            holder.dataBinding?.nameTv?.setTextColor(context.resources.getColor(com.baozhun.mall.res.R.color.main_color))
            holder.dataBinding?.checkedIv?.visibility = View.INVISIBLE
        } else {
            holder.dataBinding?.nameTv?.setTextColor(context.resources.getColor(com.baozhun.mall.res.R.color.color_333333))
            holder.dataBinding?.checkedIv?.visibility = View.INVISIBLE
        }
    }
}